<template>
  <div class="city">
    <div class="top">
      <!-- 搜索 -->
      <van-search
        v-model="searchValue"
        placeholder="城市/区域/aa"
        shape="round"
        show-action
        @cancel="cancelClick"
      />
      <!-- tab的切换：tabActive默认绑定的是索引 -->
      <van-tabs v-model:active="tabActive" color="#ff9854">
        <template v-for="(value, key, index) in allCities" :key="key">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>
    <div class="content">
      <template v-for="(value, key, index) in allCities">
        <cityGroup v-show="tabActive === key" :group-data="value" />
      </template>
    </div>
  </div>
    <div class="city">
    <div class="top">
      <!-- 搜索 -->
      <van-search
        v-model="searchValue"
        placeholder="城市/区域/位置"
        shape="round"
        show-action
        @cancel="cancelClick"
      />
      <!-- tab的切换：tabActive默认绑定的是索引 -->
      <van-tabs v-model:active="tabActive" color="#ff9854">
        <template v-for="(value, key, index) in allCities" :key="key">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>
    <div class="content">
      <template v-for="(value, key, index) in allCities">
        <cityGroup v-show="tabActive === key" :group-data="value" />
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import useCityStore from "@/store/modules/city";
import { storeToRefs } from "pinia";
import cityGroup from "./cpns/city-group.vue";
// 搜素框
const searchValue = ref("");
const router = useRouter();
const cancelClick = () => {
  router.back();
};
// Tab的切换
const tabActive = ref();
//从cityStore中获取数据
const cityStore = useCityStore();
cityStore.fetchAllCitiesData();
const { allCities } = storeToRefs(cityStore);
// 获取key从allCities获取数据，默认直接获取的数据不是响应式的，所以必须computed包裹
const currentGroup = computed(() => allCities.value[tabActive.value]);
</script>

<style lang="less" scoped>
.city {
    .top {
        position: relative;
        z-index: 9;
    }
  .content {
    // 注意-两边的空格
    height: calc(100vh - 98px);
    overflow-y: auto;
  }
}
</style>
